home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_a_d / dyndlg.zip / INITPROC.C < prev    next >
Text File  |  1992-07-21  |  5KB  |  124 lines

  1. //*-------------------------------------------------------------------------
  2. //|  Title:
  3. //|     INITPROC.C
  4. //|
  5. //|  Contents:
  6. //|     InitApplication()
  7. //|     InitInstance()   
  8. //*-------------------------------------------------------------------------
  9. #include <WINDOWS.H>
  10. #include "INITPROC.H"
  11. #include "WNDPROC.H"
  12. #include "GLOBALS.H"
  13.  
  14.  
  15. HANDLE ghInstance = NULL;
  16.  
  17.  
  18. //*----------------------------------------------------------------------------
  19. //| Title:
  20. //|     InitApplication
  21. //|
  22. //| Parameters:
  23. //|     hInstance       - Integer which uniquely identifies this instance
  24. //|                         of the application (hInstance > 0)
  25. //|     hPrevInstance   - Integer identifier of a previous instance of the
  26. //|                         application (hPrevInstance == NULL if no previous
  27. //|                         instance exists)
  28. //|
  29. //| Purpose:
  30. //|     Registers the applications window class(es) if no previous instance of
  31. //|     the application has already done so.
  32. //*----------------------------------------------------------------------------
  33. #define DEFBKGDCOLOR (COLOR_WINDOW + 1)
  34. BOOL InitApplication(HANDLE hInstance,
  35.                      HANDLE hPrevInstance)
  36. {
  37.     WNDCLASS  wc;
  38.  
  39.     // If a previous instance of this application is already loaded,
  40.     // then the window class is already registered and we are happy.
  41.     if (hPrevInstance)
  42.         return TRUE;
  43.  
  44.     // The window class is not registered yet, so we have to fill a
  45.     // window class structure with parameters that describe the       
  46.     // window class.                                                           
  47.     wc.lpszClassName = "BaseWndClass";  // String identifier for the class  
  48.     wc.lpfnWndProc = MainWndProc;       // Message handling procedure used
  49.                                         //    by windows of this class
  50.     wc.style = 0;                       // Use default class styles
  51.     wc.lpszMenuName = (LPSTR)"MyMenu";  // Use menu 
  52.     wc.hIcon   = LoadIcon  (NULL, IDI_APPLICATION); // Use a pre-defined icon
  53.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);       // Use a pre-defined cursor
  54.     wc.hbrBackground = DEFBKGDCOLOR;    // Use default window background color
  55.     wc.hInstance = hInstance;           // Instance which registered the class
  56.     wc.cbClsExtra = 0;                  // No user-defined extra-bytes
  57.                                         //    associated with this class
  58.     wc.cbWndExtra = 0;                  // No user-defined extra-bytes
  59.                                         //    associated with each window of
  60.                                         //    this class
  61.  
  62.     // Register the window class and return success/failure code.
  63.     return (RegisterClass(&wc));
  64. }
  65.  
  66.  
  67.  
  68. //*----------------------------------------------------------------------------
  69. //| Title:
  70. //|     InitInstance
  71. //|
  72. //| Parameters:
  73. //|     hInstance   - Integer which uniquely identifies this instance
  74. //|                         of the application (hInstance > 0)
  75. //|     nCmdShow    - Integer value specifying how to start app.,
  76. //|                         (Iconic [7] or Normal [1,5])
  77. //|
  78. //| Purpose:
  79. //|     Creates and displays the application's initial window(s).
  80. //*----------------------------------------------------------------------------
  81.  
  82. BOOL InitInstance(  HANDLE  hInstance,
  83.                     int     nCmdShow)
  84. {
  85.     HWND    hWnd;                       // temporary window handle             
  86.     BOOL    bStatus = FALSE;            // holds return status for function
  87.     
  88.     // Save the instance handle in global variable, which will be used in  
  89.     // many subsequent calls from this application to Windows            
  90.     ghInstance = hInstance;
  91.  
  92.     // Create a main window for this application instance
  93.     hWnd = CreateWindow(
  94.         "BaseWndClass",                 // Name of the window's class
  95.         "Sample Application",           // Text for window caption        
  96.         WS_OVERLAPPEDWINDOW,            // Window style                     
  97.         CW_USEDEFAULT,                  // Default horizontal position      
  98.         CW_USEDEFAULT,                  // Default vertical position        
  99.         700,                            // Default width                   
  100.         500,                            // Default height                   
  101.         NULL,                           // Overlapped windows have no parent
  102.         NULL,                           // Use the window class menu        
  103.         hInstance,                      // This instance owns this window  
  104.         NULL                            // Pointer (not used)
  105.     );
  106.  
  107.     // If the window was successfully created, make the window visible,
  108.     // update its client area, and return "success".  If the window
  109.     // was not created, return "failure"
  110.    if (hWnd)
  111.         { 
  112.         ShowWindow(hWnd, nCmdShow); // Set to visible & paint non-client area
  113.         UpdateWindow(hWnd);         // Tell window to paint client area
  114.         
  115.         bStatus = TRUE;             // Indicate success, default is failure
  116.         }
  117.  
  118.    return bStatus;                  // Return status code
  119. }
  120.  
  121.  
  122.  
  123.  
  124.